package com.lzy.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author lyw
 * @Date 2023/5/9-下午9:48
 */
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

  @Value("${user.avatar}")
  private String avatar;

  @Override
  public void addResourceHandlers(ResourceHandlerRegistry registry) {
    // 虚拟路径
    // http://localhost:9527/xxx/123.jpg => avatar/123.jpg
    registry.addResourceHandler("/avatar/**").addResourceLocations("file:" + avatar + "/");
  }
}
